package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.AddCsStatusLogBean;
import com.ymatou.iapi.csim.service.AddCsStatusLogCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_csstatuslog;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_csstatuslogWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_queuesessionWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*新增客服状态变更记录
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AddCsStatusLog{
	private static AddCsStatusLogBean bean;
	private static AddCsStatusLogCall call;
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private String csName=EnvSetup.getData("csName").toString();
	private ymt_csstatuslogWapper csstatislogWapper=new ymt_csstatuslogWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("新增客服状态变更记录");
	}

	@Before
	public void caseUp() {
		bean=new AddCsStatusLogBean();
		call=new AddCsStatusLogCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddCsStatusLog_1() {
		Logger.start(true,"新增客服状态变更记录-验证客服上线");
		try {
			bean.setCsId(csId);
			bean.setCsName(csName);
			bean.setRemark("测试新增客服状态变更记录_"+TestDataManager.getRandomIntNum(5));
			bean.setStatusType(0);//0:上线 1:离线
			call.setData(bean);
			call.callService();	
			//验证数据库
			String logId=call.getResult().getString("StatusLogId");
			if(logId.equals(null) || logId.equals(""))
				Logger.verifyIsNull(false, "验证返回StatusLogId不为空");
			else
			{
				ymt_csstatuslog log=csstatislogWapper.selectByPrimaryKey(call.getResult().getString("StatusLogId"));
				Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
				Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
				Logger.verifyEquals("200", call.getStatus(), "验证Status");
				
				Logger.verifyEquals(bean.getCsId(), log.getCsId(), "验证传入的CSId是否与数据库一致");
				Logger.verifyEquals(bean.getCsName(), log.getCsName(), "验证传入的CsName是否与数据库一致");
				Logger.verifyEquals(bean.getRemark(), log.getRemark(), "验证传入的Remark是否与数据库一致");
				Logger.verifyEquals(bean.getStatusType(), log.getStatusType(), "验证传入的StatusType是否与数据库一致");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddCsStatusLog_2() {
		Logger.start(true,"新增客服状态变更记录-验证客服离线");
		try {
			bean.setCsId(csId);
			bean.setCsName(csName);
			bean.setRemark("测试新增客服状态变更记录_"+TestDataManager.getRandomIntNum(5));
			bean.setStatusType(1);//0:上线 1:离线
			call.setData(bean);
			call.callService();	
			//验证数据库
			String logId=call.getResult().getString("StatusLogId");
			if(logId.equals(null) || logId.equals(""))
				Logger.verifyIsNull(false, "验证返回StatusLogId不为空");
			else
			{
				ymt_csstatuslog log=csstatislogWapper.selectByPrimaryKey(call.getResult().getString("StatusLogId"));
				Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
				Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
				Logger.verifyEquals("200", call.getStatus(), "验证Status");
				
				Logger.verifyEquals(bean.getCsId(), log.getCsId(), "验证传入的CSId是否与数据库一致");
				Logger.verifyEquals(bean.getCsName(), log.getCsName(), "验证传入的CsName是否与数据库一致");
				Logger.verifyEquals(bean.getRemark(), log.getRemark(), "验证传入的Remark是否与数据库一致");
				Logger.verifyEquals(bean.getStatusType(), log.getStatusType(), "验证传入的StatusType是否与数据库一致");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_AddCsStatusLog_3() {
		Logger.start(true,"新增客服状态变更记录-验证csId=0(研发没有做校验)");
		try {
			//bean.setCsId(0);
			bean.setCsName(csName);
			bean.setRemark("测试新增客服状态变更记录_"+TestDataManager.getRandomIntNum(5));
			bean.setStatusType(1);//0:上线 1:离线
			call.setData(bean);
			call.callService();	
			//验证数据库
			String logId=call.getResult().getString("StatusLogId");
			if(logId.equals(null) || logId.equals(""))
				Logger.verifyIsNull(false, "验证返回StatusLogId不为空");
			else
			{
				ymt_csstatuslog log=csstatislogWapper.selectByPrimaryKey(call.getResult().getString("StatusLogId"));
				Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
				Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
				Logger.verifyEquals("200", call.getStatus(), "验证Status");
				
				Logger.verifyEquals(bean.getCsId(), log.getCsId(), "验证传入的CSId是否与数据库一致");
				Logger.verifyEquals(bean.getCsName(), log.getCsName(), "验证传入的CsName是否与数据库一致");
				Logger.verifyEquals(bean.getRemark(), log.getRemark(), "验证传入的Remark是否与数据库一致");
				Logger.verifyEquals(bean.getStatusType(), log.getStatusType(), "验证传入的StatusType是否与数据库一致");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}